package com.egg.ylt.activity;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.egg.ylt.R;
import com.egg.ylt.Utils.Constants;
import com.egg.ylt.Utils.CustomUtils;
import com.egg.ylt.Utils.StatusBarUtil;
import com.egg.ylt.adapter.ADA_TransactionDetails;
import com.egg.ylt.pojo.BalletRecordEntity;
import com.egg.ylt.presenter.impl.TransactionPresenterImpl;
import com.egg.ylt.view.ITransactionView;
import com.yonyou.framework.library.base.BaseActivity;
import com.yonyou.framework.library.bean.ErrorBean;
import com.yonyou.framework.library.common.utils.AppSharedPreferences;
import com.yonyou.framework.library.common.utils.ListUtil;

import butterknife.BindView;

public class ACT_TransactionDetail extends BaseActivity<TransactionPresenterImpl> implements ITransactionView {

    @BindView(R.id.include_iv_back)
    ImageView includeIvBack;
    @BindView(R.id.include_tv_title)
    TextView includeTvTitle;
    @BindView(R.id.include_tv_right)
    TextView includeTvRight;
    @BindView(R.id.include_rl_view)
    RelativeLayout includeRlView;
    @BindView(R.id.recycler_view)
    RecyclerView recyclerView;
    @BindView(R.id.rl_target_view)
    RelativeLayout rlTargetView;

    private AppSharedPreferences mSp;

    private String mToken;
    private String mCompanyId;
    private String pageNum = "1";
    private String pageSize = "20";
    private ADA_TransactionDetails mListAdapter;

    @Override
    protected void getBundleExtras(Bundle extras) {

    }

    @Override
    protected int getContentViewLayoutID() {
        return R.layout.act_transaction_detail;
    }

    @Override
    protected View getLoadingTargetView() {
        return rlTargetView;
    }

    @Override
    protected void initViewsAndEvents() {
        StatusBarUtil.setStatusBarColor(this, R.color.ylt_whit);
        StatusBarUtil.StatusBarLightMode(this);
        CustomUtils.setImmersiveStatusBar(mContext, includeRlView);

        //设置title
        includeTvTitle.setText("交易明细");

        //获取本地用户token
        mSp = new AppSharedPreferences(mContext);
        mToken = mSp.getString(Constants.USER_TOKEN);
        mCompanyId = mSp.getString(Constants.COMPANY_ID);

        //设置listview
        initListView();

        //返回键的监听事件
        includeIvBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    private void initListView() {
        //设置布局管理器和适配器
        recyclerView.setLayoutManager(new LinearLayoutManager(mContext));
        mListAdapter = new ADA_TransactionDetails(mContext);
        recyclerView.setAdapter(mListAdapter);

        //获取用户交易明细
        mPresenter.getDataList(Constants.TOKEN, pageNum, pageSize);

    }

    @Override
    protected boolean isApplyStatusBarTranslucency() {
        return false;
    }

    @Override
    protected boolean isBindEventBusHere() {
        return false;
    }

    @Override
    protected boolean toggleOverridePendingTransition() {
        return false;
    }

    @Override
    protected TransitionMode getOverridePendingTransitionMode() {
        return null;
    }

    @Override
    protected boolean isApplyKitKatTranslucency() {
        return false;
    }

    @Override
    public void showBusinessError(ErrorBean error) {

    }

    @Override
    public void getTransactionList(BalletRecordEntity bean) {

        if (ListUtil.isListEmpty(bean.getList())) {
            toggleShowEmpty(true, R.drawable.empty_no_response, "暂无交易信息");
            return;
        }

        toggleShowEmpty(false, -1, "");

        // 设置数据
        mListAdapter.setmList(bean.getList());

    }

}
